//
//  YWHomeRecommendLittleVedioCell.m
//  YueshengToutiao
//
//  Created by jun peng on 2021/12/31.
//  Copyright © 2021 YW. All rights reserved.
//

#import "YWHomeRecommendLittleVedioCell.h"
#import "YYText.h"

@interface YWHomeRecommendLittleVedioCell ()
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIButton *playBtn;
- (IBAction)playBtnClick:(UIButton *)sender;


@property (weak, nonatomic) IBOutlet UIButton *praiseBtn;
- (IBAction)praiseBtnClick:(UIButton *)sender;


@property (weak, nonatomic) IBOutlet UIButton *shareBtn;
- (IBAction)shareBtnClick:(UIButton *)sender;


@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UIImageView *headIcon;

@property(nonatomic,strong)YWMeStatus *meStatus;


@property (weak, nonatomic) IBOutlet YWConcernBtn *concernBtn;

- (IBAction)concernBtnClick:(UIButton *)sender;


@end


@implementation YWHomeRecommendLittleVedioCell

-(YWMeStatus *)meStatus{
    //从本地加载meStatus
    _meStatus = [NSKeyedUnarchiver unarchiveObjectWithFile:YWMepath];
    
    return _meStatus;
    
}
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"YWHomeRecommendLittleVedioCell";
    YWHomeRecommendLittleVedioCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (cell == nil) {
        // 从xib中加载cell
        cell = [[[NSBundle mainBundle] loadNibNamed:@"YWHomeRecommendLittleVedioCell" owner:nil options:nil] lastObject];
    }
    return cell;
}

-(void)awakeFromNib{
    [super awakeFromNib];
    
    self.videoBgView.layer.cornerRadius = 10;
    self.videoBgView.clipsToBounds = YES;
    
    
    
    
    
    self.headIcon.layer.cornerRadius = 20;
    self.headIcon.userInteractionEnabled = YES;
    UITapGestureRecognizer *headIconTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(headIconTap)];
    [self.headIcon addGestureRecognizer:headIconTap];
    
    //内容label
//    self.cellLabel.numberOfLines = 0;  //设置多行显示
//    self.cellLabel.preferredMaxLayoutWidth = Wi - 30;//设置最大的宽度
    
}

-(void)headIconTap{
    if ([self.delegate respondsToSelector:@selector(listCell:didClickHeadWithStatus:)]) {
        [self.delegate listCell:self didClickHeadWithStatus:self.status];
    }
}

-(void)setStatus:(YWGetNewsDataStatus *)status{
    
    _status = status;
    
    if ([status.Img isKindOfClass:[NSNull class]] || status.Img == nil) {
        status.Img = @"";
    }
    
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:status.Img]];
    
    self.timeLabel.text = status.AddDateTime;
    
    self.nameLabel.text = status.Author;
    
    if ([status.AuthorImg isKindOfClass:[NSNull class]] || status.AuthorImg == nil) {
        status.AuthorImg = @"";
    }
    
    [self.headIcon sd_setImageWithURL:[NSURL URLWithString:status.AuthorImg] placeholderImage:[UIImage imageNamed:@"头像3"]];
    
    if (status.IsLike.integerValue == 1) {
        
        [self.praiseBtn setImage:[UIImage imageNamed:@"赞"] forState:UIControlStateNormal];
        
        [self.praiseBtn setTitleColor:mainColor forState:UIControlStateNormal];
        [self.praiseBtn setTitle:[NSString stringWithFormat:@"%@",status.Praise] forState:UIControlStateNormal];
    }
    else{
        
         [self.praiseBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        
        [self.praiseBtn setImage:[UIImage imageNamed:@"赞-未选中"] forState:UIControlStateNormal];
        [self.praiseBtn setTitle:[NSString stringWithFormat:@"点赞"] forState:UIControlStateNormal];
    }
    
    
    
        NSString *totalString = status.Title;
        
    NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:8];
    
    
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:totalString attributes: @{NSForegroundColorAttributeName: YWColor(51, 51, 51),NSParagraphStyleAttributeName:paragraphStyle}];

    self.titleLabel.attributedText = string;
     
     
    //判断是不是第一个cell
        if (status.isFirstStatus) {
            UIImageView *bgView = [[UIImageView alloc] init];
            bgView.image = [UIImage yf_resizingWithImaName:@"firstCellBg"];
            self.backgroundView = bgView;
            self.backgroundColor = [UIColor clearColor];
        }
        else{
            self.backgroundView = nil;
            self.backgroundColor = [UIColor whiteColor];
        }
    
    if (status.IsFocus.intValue == 1) {
        self.concernBtn.isSelect = YES;
    }
    else{
        
        self.concernBtn.isSelect = NO;
    }
    if (status.isClassify == 1 || status.isTeacherList == 1) {
        self.concernBtn.hidden = YES;
    }
    else{
        
            self.concernBtn.hidden = NO;
        
    }
    
    
    
}

- (IBAction)praiseBtnClick:(UIButton *)sender {
    
    if ([self.delegate respondsToSelector:@selector(listCell:didClickPraiseWithDataStatus:)]) {
        [self.delegate listCell:self didClickPraiseWithDataStatus:self.status];
    }
}


- (IBAction)shareBtnClick:(UIButton *)sender {
    
    if ([self.delegate respondsToSelector:@selector(listCell:didClickShareWithDataStatus:)]) {
        [self.delegate listCell:self didClickShareWithDataStatus:self.status];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    
}

-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
    
}


- (IBAction)playBtnClick:(UIButton *)sender {
    
    if ([self.delegate respondsToSelector:@selector(listCell:didClickPlayLittleVideoWithDataStatus:)]) {
        [self.delegate listCell:self didClickPlayLittleVideoWithDataStatus:self.status];
    }
    
}

- (IBAction)concernBtnClick:(UIButton *)sender {
    
 
    
    if ([self.delegate respondsToSelector:@selector(listCell:didConcernWithStatus:)]) {
        [self.delegate listCell:self didConcernWithStatus:self.status];
    }
    
    
}



//-(void)startPlay{
//
//    YWVideoPlayerManager *playerManager = [YWVideoPlayerManager sharevideoPlayerManager];
//
//    [playerManager startPlayWithUrl:self.status.FileUrl view:self.videoView complication:^{
//
//    } startPlay:^{
//
//    } progress:^(float progress, float duration, float playable) {
//
//    } end:^{
//
//    } loading:^{
//
//    }];
//}
//
//
//-(void)stopPlay{
//
//    YWVideoPlayerManager *playerManager = [YWVideoPlayerManager sharevideoPlayerManager];
//
//    [playerManager stopPlayWithComplication:^{
//
//    }];
//
//}


@end
